<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","upp_sch_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.DelLab.SchName.value=val;
document.getElementById("List").innerHTML="";
var xmlhttp;    
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("L_id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","labids.php?q="+val,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function DeleteVerification()
{
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   
   else
   {
   ?>   
var Lab_Id=document.forms["DelLab"]["Lab_Id"].value;
var School_Id=document.forms["DelLab"]["SchName"].value;

if (Lab_Id=="Select One"||School_Id=="")
  {
  alert("Please select the Lab id and School's name to delete!");
  return false;
  }
  
if (Lab_Id!="Select One"&&School_Id!="")
{
var r=confirm("Are you sure to delete this?");
if (r==true)
  {
  return true;
 
 }

if(r==false)
  {
 return false;
  }
}
}
</script>

</head>
<body>
  <?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
 <div id="lefttablereg">
<form  name="DelLab" action="#" method="POST" onSubmit="return DeleteVerification()">
<?php
if(isset($_POST['Delete']))
{
require_once 'DEL.php';
}
?>
  <table width="489" border="0" class="tablefontv">
    <tr>
      <td height="22" colspan="6"  scope="row" class="err">
        <?php
      if(isset($_POST['Delete']))
{
	if(isset($_SESSION['errorin']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errornorow']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
	if(isset($_SESSION['errornot']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot'];
		unset($_SESSION['errornot']);
	}
	if(isset($_SESSION['errornot2']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot2'];
		unset($_SESSION['errornot2']);
	}
}   
?>
</td>
</tr>
    <tr>
      <th width="36" rowspan="3"  scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <th width="100" height="29"  scope="row" bgcolor="#6AB5FF">School's Name</th>
	  <td width="14" align="left" scope="row" bgcolor="#6AB5FF">:-</td>
      <td colspan="2" bgcolor="#999999">
      <?php
	 	if($_SESSION['Access_Type']=="Teacher in Charge")
{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id']; 
    $snam=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
}
	 echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' size='40' readonly='readonly'/>";
}
	else if($_SESSION['Access_Type']=="Administrator")
{
	if(!isset($SchName))
	{
		$snam=mysql_query("SELECT * FROM school WHERE School_Id='$School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
	}
	    echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' size='40'/>";
}
	  ?></td>
      <td width="168" bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <th height="24" scope="row" bgcolor="#6AB5FF">Lab Id</th>
      <td align="left" scope="row" bgcolor="#6AB5FF">:-</td>
      <td colspan="2" bgcolor="#999999">
	  <div id="L_id">
	  <select name="Lab_Id" id="Lab_Id">
        <?php
	  
	  if(isset($_POST['Delete']))
	  {
	echo '<option value="'.$Lab_Id.'">'.$Lab_Id.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	   if($Schoo_Id!="")
	  {
	  $lab=mysql_query("SELECT DISTINCT(Lab_Id) FROM lab WHERE School_Id='$Schoo_Id'");
	  }
	  if($Schoo_Id=="")
	  {
	  $lab=mysql_query("SELECT DISTINCT(Lab_Id) FROM lab");
	  }
  while($row=mysql_fetch_array($lab))
  {
	 $La_Id=$row['Lab_Id'];
	  if($La_Id!=$Lab_Id)
{
	echo '<option value="'.$La_Id.'">'.$La_Id.'</option>';
}
	  
  }	  ?>
      </select></div></td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <th height="24" colspan="5" scope="row" bgcolor="#6AB5FF"><a href="DelLab.php" class="reset">Reset |</a>
        <input name="Delete" align="middle" type="submit" value="Delete" class="buttonok"/></th>
	  </tr>
    
  </table>

  <br/>
  
   </form>
  <?php
   	   if(isset($_POST['Delete']))
{
if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
   {
	      
	 if($Lab_Id!="Select One"&&$School_Id!="Select One"&&$Date_of_commencement!=""&&$Source_Of_Power!="")
  {   
      echo '<table width="458" border="0" class="tablefontv">';
       echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "
		Source Of Power:";
		echo '</th>';
        echo '<td width="144">';
		echo $Source_Of_Power;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="25" scope="row">';
		echo "
		Telephone Number:";
		echo '</th>';
        echo '<td>';
		echo $Tp_Number;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="25" scope="row">';
		echo "
		Account Number:";
		echo '</th>';
        echo '<td>';
		echo $Account_Number;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="25" scope="row">';
		echo "Date of commencement :";
		echo '</th>';
       echo '<td>';
	   echo  $Date_of_commencement;
	   echo '</td>';
      echo '</tr>';
	  if($Internet_Facilities!="")
	  {
      echo '<tr>';
        echo '<th height="25" scope="row">';
		echo "Internet_Facilities:"; 
		echo '</th>';
        echo '<td>';
		echo $Internet_Facilities;            
        echo '</td>';
      echo '</tr>';
	  }
	  if($Availability_Of_LAN!="")
	  {
	   echo '<tr>';
        echo '<th height="25" scope="row">';
		echo "Availability of LAN:"; 
		echo '</th>';
        echo '<td>';
		echo $Availability_Of_LAN;            
        echo '</td>';
      echo '</tr>';
	  }
      echo '<tr>';
        echo '<th height="25" scope="row">';
		echo "Lab Type:"; 
		echo '</th>';
        echo '<td>';
		echo $Lab_Type;
		echo '</td>';
      echo '</tr>'; 
   }
    echo '</table>';
	
	}
	}
    ?>
	</div>
 <div id="righttablereg">
  <div class="suggestionListsch" id="List"></div>
 </div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">LABS</h2>
            </div>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
<?php
	 }
  
?>
</body>
</html>